#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll _f[20][20][4000];
int val[20];

ll f(int pos,int pivot,int torque,bool lim){
    if(pos<=0) return torque==0?1:0;
    if(torque<0) return 0;
    if((!lim)&&_f[pos][pivot][torque]!=-1) return _f[pos][pivot][torque];

    int mx=lim?val[pos]:9;
    ll ans=0;
    for(int i=0;i<=mx;i++){
        ans+=f(pos-1,pivot,torque+i*(pos-pivot),lim&&i==mx);
    }
    if(!lim) _f[pos][pivot][torque]=ans;
    return ans;
}

ll solve(ll x){
    if(x<0) return 0;
    int len=0;
    while(x) val[++len]=x%10,x/=10;
    ll ans=0;
    for(int i=1;i<=len;i++) ans+=f(len,i,0,1);
    ans-=len-1; //0
    return ans;
}

ll read(){
    char c;ll r;bool f=0;
    for(c=getchar();c>'9'||c<'0';c=getchar()) if(c=='-') f=1;
    for(r=0;c>='0'&&c<='9';c=getchar()) r=r*10+c-'0';
    if(f) return -r;
    else return r;
}

void print(const ll &x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

int main(){
    int T;
    T=read();

    memset(_f,-1,sizeof _f);
    while(T--){
        ll x,y;
        x=read();y=read();
        print(solve(y)-solve(x-1));
        putchar('\n');
    }
}
